﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace Core.Unity {
    public class CommandManagerWpf : CommandManager {
        Dictionary<string, ICommand> _commands = new Dictionary<string, ICommand>();

        public Dictionary<string, ICommand> Commands {
            get {
                return _commands;
            } 
        }

        public CommandManagerWpf() {

        }

        public void Add(string id, CommandAdapter cmd) {
            base.Add(id, cmd.Command);
            _commands.Add(id, cmd);
        }

        public void Remove(string id) {
            base.Remove(id);
            if (_commands.Keys.Contains(id)) {
                _commands.Remove(id);
            }
        }

        public ICommand FindCommand(string id) {
            if (_commands.Keys.Contains(id)) {
                return _commands[id];
            }
            return null;
        }

        public ICommand this[string id] {
            get {
                return this.FindCommand(id);
            }
        }

        public void CreateCommands(object hook) {
            _commands.ToList().ForEach(a => (a.Value as CommandAdapter).OnCreate(hook));
        }
    }
}
